package lookie.swing.tree.support.file;

import java.io.File;

import javax.swing.Icon;
import javax.swing.filechooser.FileSystemView;
import javax.swing.tree.TreeNode;

import lookie.swing.tree.render.LabelProvider;


public class FileTreeNodeLabelProvider implements LabelProvider {

	private static final FileSystemView fsv = FileSystemView
			.getFileSystemView();

	private boolean useNativeIcons;

	public FileTreeNodeLabelProvider() {
		this(true);
	}

	public FileTreeNodeLabelProvider(boolean useNativeIcons) {
		super();
		this.useNativeIcons = useNativeIcons;
	}

	public Icon getIcon(TreeNode node) {
		if (useNativeIcons) {
			if (node instanceof FileTreeNode) {
				File file = ((FileTreeNode) node).getFile();
				if (file != null) {
					return fsv.getSystemIcon(file);
				}
			}
		}
		return null;
	}

	public String getText(TreeNode node) {
		if (node instanceof FileTreeNode) {
			File file = ((FileTreeNode) node).getFile();
			if (file != null) {
				return fsv.getSystemDisplayName(file);
			}
		}
		return null;
	}

}
